package org.swimv2.model;

import java.io.Serializable;
import javax.persistence.*;

import java.util.List;


/**
 * The persistent class for the persona database table.
 * 
 */

@NamedQueries({
@NamedQuery(name="Persona.findByUsername", query="SELECT p FROM Persona p WHERE p.userID =:username"),
@NamedQuery(name="Persona.findByEmail", query="SELECT p FROM Persona p WHERE p.e_mail =:email"),
@NamedQuery(name="Persona.findByNomeCognome", query="SELECT p FROM Persona p WHERE p.nome=:nome AND p.cognome=:cognome"),
@NamedQuery(name="Persona.findByAbRegDisp", query="SELECT p FROM Persona p,Abilita a WHERE a.nome=:abilita AND (p MEMBER OF a.personas) AND p.regione=:regione AND p.disponibilita>=:disponibilita"),
@NamedQuery(name="Persona.findByAbDisp", query="SELECT p FROM Persona p,Abilita a WHERE a.nome=:abilita AND (p MEMBER OF a.personas) AND p.disponibilita>=:disponibilita"),
@NamedQuery(name="Persona.findAmiciByUsername", query="SELECT p FROM Persona p,Persona p1 WHERE ((p MEMBER OF p1.personas1) OR (p MEMBER OF p1.personas2)) AND p1.userID=:userId"),
@NamedQuery(name="Persona.findByAbRegDispUt", query="SELECT p FROM Persona p, Persona q, Abilita a WHERE q.userID=:richiedente AND (p MEMBER OF q.personas1) AND a.nome=:abilita AND (p MEMBER OF a.personas) AND p.regione=:regione AND p.disponibilita>=:disponibilita"),
@NamedQuery(name="Persona.findByAbDispUt", query="SELECT p FROM Persona p, Persona q, Abilita a WHERE q.userID=:richiedente AND (p MEMBER OF q.personas1) AND a.nome=:abilita AND (p MEMBER OF a.personas) AND p.disponibilita>=:disponibilita")
})
@Entity
public class Persona implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	private String userID;

	private String cognome;

	private byte disponibilita;

	@Column(name="`e-mail`")
	private String e_mail;

	@Lob
	private byte[] foto;

	private String nome;

	private String password;

	private String regione;

	private String ruolo;

	//bi-directional many-to-many association to Persona
	@ManyToMany
	@JoinTable(
		name="amico"
		, joinColumns={
			@JoinColumn(name="userID_B")
			}
		, inverseJoinColumns={
			@JoinColumn(name="userID_A")
			}
		)
	private List<Persona> personas1;

	//bi-directional many-to-many association to Persona
	@ManyToMany(mappedBy="personas1")
	private List<Persona> personas2;

	//bi-directional many-to-one association to Feedback
	@OneToMany(mappedBy="persona")
	private List<Feedback> feedbacks;

	//bi-directional many-to-one association to Lavoro
	@OneToMany(mappedBy="persona")
	private List<Lavoro> lavoros1;

	//bi-directional many-to-one association to Messaggio
	@OneToMany(mappedBy="persona1")
	private List<Messaggio> messaggios1;

	//bi-directional many-to-one association to Messaggio
	@OneToMany(mappedBy="persona2")
	private List<Messaggio> messaggios2;

	//bi-directional many-to-many association to Lavoro
	@ManyToMany
	@JoinTable(
		name="partecipazione"
		, joinColumns={
			@JoinColumn(name="userIDcollaboratore")
			}
		, inverseJoinColumns={
			@JoinColumn(name="IDLavoroSvolto")
			}
		)
	private List<Lavoro> lavoros2;

	//bi-directional many-to-many association to Abilita
	@ManyToMany
	@JoinTable(
		name="possesso"
		, joinColumns={
			@JoinColumn(name="userIDpossessore")
			}
		, inverseJoinColumns={
			@JoinColumn(name="NomeAbilita")
			}
		)
	private List<Abilita> abilitas;

	//bi-directional many-to-many association to Richiestanuovaabilita
	@ManyToMany
	@JoinTable(
		name="richideab"
		, joinColumns={
			@JoinColumn(name="userIDrichiedente")
			}
		, inverseJoinColumns={
			@JoinColumn(name="NomeAbilita")
			}
		)
	private List<Richiestanuovaabilita> richiestanuovaabilitas;

	//bi-directional many-to-one association to Richiestaamicizia
	@OneToMany(mappedBy="persona1")
	private List<Richiestaamicizia> richiestaamicizias1;

	//bi-directional many-to-one association to Richiestaamicizia
	@OneToMany(mappedBy="persona2")
	private List<Richiestaamicizia> richiestaamicizias2;

	//bi-directional many-to-one association to Richiestapartecipazionelavoro
	@OneToMany(mappedBy="persona")
	private List<Richiestapartecipazionelavoro> richiestapartecipazionelavoros;

	public Persona() {
	}

	public String getUserID() {
		return this.userID;
	}

	public void setUserID(String userID) {
		this.userID = userID;
	}

	public String getCognome() {
		return this.cognome;
	}

	public void setCognome(String cognome) {
		this.cognome = cognome;
	}

	public byte getDisponibilita() {
		return this.disponibilita;
	}

	public void setDisponibilita(byte disponibilita) {
		this.disponibilita = disponibilita;
	}

	public String getE_mail() {
		return this.e_mail;
	}

	public void setE_mail(String e_mail) {
		this.e_mail = e_mail;
	}

	public byte[] getFoto() {
		return this.foto;
	}

	public void setFoto(byte[] foto) {
		this.foto = foto;
	}

	public String getNome() {
		return this.nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getRegione() {
		return this.regione;
	}

	public void setRegione(String regione) {
		this.regione = regione;
	}

	public String getRuolo() {
		return this.ruolo;
	}

	public void setRuolo(String ruolo) {
		this.ruolo = ruolo;
	}

	public List<Persona> getPersonas1() {
		return this.personas1;
	}

	public void setPersonas1(List<Persona> personas1) {
		this.personas1 = personas1;
	}

	public List<Persona> getPersonas2() {
		return this.personas2;
	}

	public void setPersonas2(List<Persona> personas2) {
		this.personas2 = personas2;
	}

	public List<Feedback> getFeedbacks() {
		return this.feedbacks;
	}

	public void setFeedbacks(List<Feedback> feedbacks) {
		this.feedbacks = feedbacks;
	}

	public List<Lavoro> getLavoros1() {
		return this.lavoros1;
	}

	public void setLavoros1(List<Lavoro> lavoros1) {
		this.lavoros1 = lavoros1;
	}

	public List<Messaggio> getMessaggios1() {
		return this.messaggios1;
	}

	public void setMessaggios1(List<Messaggio> messaggios1) {
		this.messaggios1 = messaggios1;
	}

	public List<Messaggio> getMessaggios2() {
		return this.messaggios2;
	}

	public void setMessaggios2(List<Messaggio> messaggios2) {
		this.messaggios2 = messaggios2;
	}

	public List<Lavoro> getLavoros2() {
		return this.lavoros2;
	}

	public void setLavoros2(List<Lavoro> lavoros2) {
		this.lavoros2 = lavoros2;
	}

	public List<Abilita> getAbilitas() {
		return this.abilitas;
	}

	public void setAbilitas(List<Abilita> abilitas) {
		this.abilitas = abilitas;
	}

	public List<Richiestanuovaabilita> getRichiestanuovaabilitas() {
		return this.richiestanuovaabilitas;
	}

	public void setRichiestanuovaabilitas(List<Richiestanuovaabilita> richiestanuovaabilitas) {
		this.richiestanuovaabilitas = richiestanuovaabilitas;
	}

	public List<Richiestaamicizia> getRichiestaamicizias1() {
		return this.richiestaamicizias1;
	}

	public void setRichiestaamicizias1(List<Richiestaamicizia> richiestaamicizias1) {
		this.richiestaamicizias1 = richiestaamicizias1;
	}

	public List<Richiestaamicizia> getRichiestaamicizias2() {
		return this.richiestaamicizias2;
	}

	public void setRichiestaamicizias2(List<Richiestaamicizia> richiestaamicizias2) {
		this.richiestaamicizias2 = richiestaamicizias2;
	}

	public List<Richiestapartecipazionelavoro> getRichiestapartecipazionelavoros() {
		return this.richiestapartecipazionelavoros;
	}

	public void setRichiestapartecipazionelavoros(List<Richiestapartecipazionelavoro> richiestapartecipazionelavoros) {
		this.richiestapartecipazionelavoros = richiestapartecipazionelavoros;
	}
	
	@Override
	public boolean equals(Object obj){
		if(obj instanceof Persona){
			return ((Persona) obj).getUserID().equals(this.getUserID());
		}
		return false;
	}
	
	@Override
	public int hashCode(){
		int hash = 3;
		hash = 59 * hash + (this.userID != null ? this.userID.hashCode() : 0);
		return hash;
	}
}